package com.sinopec.android.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtil {
	 /**
     * 根据当前给定的日期获取当前天是星期几(中国版的)
     * 
     * @param date
     *            任意时间
     * @return
     */
    public static String getChineseWeek(Date date) {
     final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
       "星期六" };
     Calendar c = getCalendar(date);
     int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
     return dayNames[dayOfWeek - 1];

    }
	/**
	 * @description 【获取当前日期日历】
	 * @param date
	 * @return
	 * @author zhangyun
	 */
	public static Calendar getCalendar(Date date){
		if (date == null)
			return null;
		Calendar c = new GregorianCalendar();
		c.setTime(date);
		return c;
	}
	
	
	/**
	 * 
	 * @param date 格式 2011-5-12
	 * @return 星期
	 */
	public static  String getWeek(String date){
		String[] weeks = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日",}; 
		Date dat = null;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			dat = simpleDateFormat.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		if(dat==null){
			return "";
		}
        Calendar cal = Calendar.getInstance();
        cal.setTime(dat);          
        int w=cal.get(Calendar.DAY_OF_WEEK)-1;
        if(w==0)w=7;
        return weeks[w-1];
	}
}
